package algorithm.sort;


public class NumberSort {
	public static void main(String[] args) {
		int[] a = new int[args.length];
		for(int i=0;i<args.length;i++){
			a[i] = Integer.parseInt(args[i]);
		}
		
		print(a);
		selectsort(a);
		print(a);
	}
	
	private static void maopaosort(int[] a){
		int temp;
		int i;
		int j;
		for(i=0;i<a.length;i++){
			for(j=i+1;j<a.length;j++){
				if(a[i]<a[j]){
					temp = a[i];
					a[i] = a[j];
					a[j] = temp;
				}
			}
			
		}
	}
	
	//改进算法，提升效率
	private static void selectsort(int[] a){
		int temp,i,j,k;
		for(i=0;i<a.length;i++){
			k=i;
			for(j=k+1;j<a.length;j++){
				if(a[k]>a[j]){
					k =j;
				}
			}
		if(k!=i){
			temp = a[i];
			a[i] = a[k];
			a[k] = temp;
		}
		}
	}
	
	
	private static void print(int[] a){
		for(int i=0;i<a.length;i++){
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}
}
